import React, { Component } from 'react';
import { observer, inject } from "mobx-react";
import styles from './index.module.less';
import { renderEmpty } from '../commonRender'
import { TaskDetailContent } from '../../task/taskDetail'

@inject(({ taskState }) => ({ taskState }))
@observer
class SideTaskInfo extends Component {

    componentDidMount() {
        document.addEventListener('refleshSideTask', this.refleshListener);
    }

    componentWillUnmount() {
        document.removeEventListener('refleshSideTask', this.refleshListener);
    }

    refleshListener = (event) => {
        this.props.taskState.getDetail(event.detail, true);
    }

    render() {
        // type 1: 在聊天页面侧边栏；2: 显现在项目页面侧边栏；3: 显现在任务页面侧边栏
        const { type, isFromProjectTaskItemClick } = this.props;
        const {
            detailData: detailData1, detailDataForSide: detailData2,
            repeatList, aheadList,
            saveinfo, saveRemind, manageMember, deleteFiles, alarmTaskList, complete, restart
        } = this.props.taskState;
        const detailData = (isFromProjectTaskItemClick || type === 2) ? detailData2 : detailData1;

        // if(detailData) {
        //     console.log(JSON.parse(JSON.stringify(detailData)));
        // }
        if (!detailData) return renderEmpty('暂无数据');

        return (
            <div className={styles.info}>
                <div className={styles.taskContent}>
                    <TaskDetailContent
                        col={1}
                        isShowInSlider
                        detailData={detailData}
                        saveinfo={saveinfo}
                        alarmTaskList={alarmTaskList}
                        saveRemind={saveRemind}
                        repeatList={repeatList}
                        aheadList={aheadList}
                        manageMember={manageMember}
                        deleteFiles={deleteFiles}
                        complete={complete}
                        restart={restart}
                    />
                </div>
            </div>
        );
    }
}

export default SideTaskInfo